package main

import (
	"log"
	"net"
	"net/rpc"
)

const UserServiceName = "path/user.UserService"

type UserServiceInterface interface {
	Say(request string, reply *string) error
}

func RegisterUserService(s UserServiceInterface) error {
	return rpc.RegisterName(UserServiceName, s)
}

type UserService struct {
}

func (s *UserService) Say(request string, reply *string) error {
	*reply = "hi," + request
	return nil
}

func main() {
	err := RegisterUserService(new(UserService))
	if err != nil {
		panic(err)
	}
	listener, err := net.Listen("tcp", ":8012")
	if err != nil {
		panic(err)
	}
	for {
		conn, err := listener.Accept()
		if err != nil {
			log.Fatal(err)
		}

		go rpc.ServeConn(conn)
	}

}
